package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.LiveDataAlarm;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/3/18
 *
 * 塔吊、升降机、环境设备实时数据预警数据列表适配器
 */

public class LiveDataAlarmAdapter extends RecyclerAdapter<LiveDataAlarm, LiveDataAlarmAdapter.LiveDataAlarmViewHolder> {


    public LiveDataAlarmAdapter(Context context, List<LiveDataAlarm> dataList) {
        super(context, dataList);
    }

    @Override
    public LiveDataAlarmViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_data_list_live_alarm, null);
        return new LiveDataAlarmViewHolder(view);
    }

    @Override
    public void onBindViewHolder(LiveDataAlarmViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class LiveDataAlarmViewHolder extends RecyclerAdapter.BaseViewHolder<LiveDataAlarm>{
        @BindView(R.id.alarm_rl)
        RelativeLayout alarmRl;
        @BindView(R.id.alarm_img)
        ImageView alarmImg;
        @BindView(R.id.alarm_tv)
        HXTextView alarmTv;

        public LiveDataAlarmViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            LiveDataAlarm liveDataAlarm = dataList.get(position);
            switch (liveDataAlarm.getType()){//  1 正常 2预警 3报警 4违章
                case 1:
                    alarmRl.setBackgroundColor(getColor(R.color.color_1A4CCC62));
                    alarmImg.setImageResource(R.mipmap.icon_normal);
                    break;
                case 2:
                    alarmRl.setBackgroundColor(getColor(R.color.color_1AFD9D00));
                    alarmImg.setImageResource(R.mipmap.icon_warning);
                    break;
                case 3:
                    alarmRl.setBackgroundColor(getColor(R.color.color_1AFD9D00));
                    alarmImg.setImageResource(R.mipmap.icon_alarm);
                    break;
                case 4:
                    alarmRl.setBackgroundColor(getColor(R.color.color_1AFD9D00));
                    alarmImg.setImageResource(R.mipmap.icon_violation);
                    break;
            }
            alarmTv.setText(liveDataAlarm.toString());
        }
    }

    private int getColor(int colorId){
        return context.getResources().getColor(colorId);
    }
}
